﻿using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Speech.AudioFormat;
using System.Speech.Recognition;
using System.Text;
using System.Threading.Tasks;

namespace NuiDicomPlayer.Nui.Speech
{
    

    public class SpeechCommander
    {

        public event EventHandler<SpeechRecogised> OnSpeechRecognised;

        private const string RecognizerId = "SR_MS_en-US_Kinect_10.0";
        System.Speech.Recognition.SpeechRecognitionEngine _recognizer = new System.Speech.Recognition.SpeechRecognitionEngine();

        public void Start(KinectSensor sensor)
        {

            Choices ch = new Choices();
            ch.Add("kinect show shadow");
            ch.Add("kinect hide shadow");
            ch.Add("kinect load new file");
            ch.Add("kinect show record");
            ch.Add("kinect close");
            ch.Add("kinect play");
            ch.Add("kinect reverse");
            ch.Add("kinect stop");
            ch.Add("kinect show sagital");
            ch.Add("kinect show axial");
            ch.Add("kinect show coronal");
            ch.Add("kinect reset brightness");
            ch.Add("kinect reset contrast");
            ch.Add("kinect zoom all");
            ch.Add("kinect quit");
            _recognizer.SpeechRecognized += _recognizer_SpeechRecognized;           
            _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(ch)));

            
            _recognizer.SetInputToDefaultAudioDevice();

           
            new Task(new Action(() => { 
            
                while(true) 
                    _recognizer.Recognize(TimeSpan.FromMilliseconds(3000));
            
            })).Start();

        }
        void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            
            if (OnSpeechRecognised != null) this.OnSpeechRecognised(this,new SpeechRecogised(e.Result));
        }

    }

   
}
